#include "MatrixSave.h"

#include <QFile>
#include <QTextStream>
#include <QString>

MatrixSave::MatrixSave()
{

}

MatrixSave::~MatrixSave()
{

}

int MatrixSave::save(Output output,Layer mag)
{
  QFile filex,filey,filez;
  QTextStream phdfilex(&filex);
  QTextStream phdfiley(&filey);
  QTextStream phdfilez(&filez);
  QString filename;
  
  //mz matrix
  filename=output.getPhDFile();
  filename.append("_mz.txt");
  filez.setFileName(filename);
  filez.open(QIODevice::Append);
  if(mag.getFrozen()==true)
    phdfilez<<endl;
  else phdfilez<<mag.getMag().getZ()<<"\t";
  filez.close();

  //my matrix
  filename=output.getPhDFile();
  filename.append("_my.txt");
  filey.setFileName(filename);
  filey.open(QIODevice::Append);
  if(mag.getFrozen()==true)
    phdfiley<<endl;
  else phdfiley<<mag.getMag().getX()<<"\t";
  filey.close();
    
  //mx matrix
  filename=output.getPhDFile();
  filename.append("_mx.txt");
  filex.setFileName(filename);
  filex.open(QIODevice::Append);
  if(mag.getFrozen()==true)
    phdfilex<<endl;      
  else phdfilex<<mag.getMag().getX()<<"\t";
  filex.close();
 
  return 0;
}

int MatrixSave::doublesave(Output output,double value)
{
  QFile file(output.getPhDFile());
  QTextStream phdfile(&file);
  file.open(QIODevice::Append);
  phdfile<<value<<"\t";
  file.close();
  return 0;
}


int MatrixSave::stringsave(Output output,QString value)
{
  QFile file(output.getPhDFile());
  QTextStream phdfile(&file);
  file.open(QIODevice::Append);
  phdfile<<value;
  file.close();
  return 0;
}
